#ifndef __DRIVER_TM1637_H__
#define __DRIVER_TM1637_H__

#include <Arduino.h>

#define DELAY   delayMicroseconds(2)
#define WEI     6

// https://item.szlcsc.com/datasheet/TM1637/20710.html
class TM1637{ 
public:
  TM1637(uint8_t CLK, uint8_t DIO);
  void Clear(void);
  void Display6Num(uint32_t num);
  void Display4Num(uint8_t offset, uint32_t num);
  void DisplayDash4Num(uint8_t offset, uint32_t num);
  void DisplayNum(uint8_t offset, uint32_t num);
  void SetBrightness(uint8_t br);
  uint8_t GetBrightness(void);
  void SetSegmentDisplayNum(uint8_t Seg, char cont);
  void SetFlip(bool f);

private:
  uint8_t swap_bits(uint8_t dat);
  void driver_tm1637_cmd(uint8_t dat);
  void driver_tm1637_start(void);
  void driver_tm1637_stop(void);
  void Display1Num(uint8_t posi, uint8_t num);

  uint8_t pin_clk;
  uint8_t pin_dio;
  bool flip;
  uint8_t brightness;
};

#endif
